import request from '@/utils/http'
import { useAppStore } from '@/store'

const baseURL = import.meta.env.VITE_SLOTS_API
const PATH = '/portal'
const headers = () => {
	const appStore = useAppStore()
	return {
		sRegion: appStore.region || 1,
		sLanguage: appStore.lang || 'en'
	}
}
// request.defaults.headers.common = { ...request.defaults.headers.common, ...headers() }

export function liveWins(params: any) {
	return request({
		headers: headers(),
		baseURL,
		url: PATH + `/liveWins/${params.type}`,
		method: 'get'
	})
}
export function bannersReq(isSlots: boolean, params: any) {
	return request({
		headers: headers(),
		baseURL,
		url: isSlots ? `${PATH}/banner/list` : `/casino/${PATH}/games/banner/list`,
		method: 'get',
		params
	})
}
export function recommendsReq() {
	return request({
		headers: headers(),
		baseURL,
		url: PATH + '/recommended/list',
		method: 'post'
	})
}

// game all
export function collectionsReq(params: any) {
	return request({
		// headers: Object.assign(headers(), { page: params.page || 1 }),
		headers: headers(),
		baseURL,
		url: PATH + '/games/favorite',
		method: 'get',
		params
	})
}
export function newGamesReq(params: any) {
	return request({
		headers: headers(),
		baseURL,
		url: PATH + '/newGame/list/' + params.page,
		method: 'get',
		params
	})
}
export function popularsReq(params: any) {
	return request({
		headers: headers(),
		baseURL,
		url: PATH + '/popular/list2/' + params.page,
		method: 'get',
		params
	})
}
export function promosReq(params: any) {
	return request({
		headers: headers(),
		baseURL,
		url: PATH + '/promotion/list/' + params.page,
		method: 'get',
		params
	})
}
export function rtpsReq(params: any) {
	return request({
		headers: headers(),
		baseURL,
		url: PATH + '/rtp/list/' + params.page,
		method: 'get',
		params
	})
}
export function aToZReq(params: any) {
	return request({
		headers: headers(),
		baseURL,
		url: PATH + '/a2z/list/' + params.page,
		method: 'get',
		params
	})
}
export function zToAReq(params: any) {
	return request({
		headers: headers(),
		baseURL,
		url: PATH + '/z2a/list/' + params.page,
		method: 'get',
		params
	})
}

export function collectGame(params: any) {
	return request({
		headers: headers(),
		baseURL,
		url: params.cancelFlag ? PATH + '/favorite/cancel' : PATH + '/favorite/add',
		method: 'post',
		data: {
			gameId: params.id
		}
	})
}
export function liveBigReq(data: any) {
	return request({
		headers: headers(),
		baseURL,
		url: PATH + '/selectAllBigWins',
		method: 'post',
		data
	})
}
export function goinGame(id: any, params: any) {
	return request({
		headers: headers(),
		baseURL,
		url: PATH + '/goinGame/v1/' + id,
		method: 'get',
		params
	})
}

export function getSlotsStatistic(data: any) {
	return request({
		headers: headers(),
		baseURL,
		url: PATH + '/userInfo/statisticsList',
		method: 'post',
		data
	})
}

export function getRecentGames(data: any) {
	return request({
		headers: headers(),
		baseURL,
		url: PATH + '/searchRecentGames',
		method: 'post',
		data
	})
}

export function getRecentOtherGames(data: any) {
	return request({
		headers: headers(),
		baseURL,
		url: PATH + `/searchOtherRecentGames`,
		method: 'post',
		data
	})
}

export function getCurrentGameData(data: any) {
	console.log(data)
	return request({
		headers: headers(),
		baseURL,
		url: PATH + `/betRecord/gamePage/${data.id}`,
		method: 'get'
	})
}

export function getSlotsRecordList(params: any) {
	return request({
		headers: headers(),
		baseURL,
		url: PATH + `/betRecord/list`,
		method: 'get',
		params
	})
}

export function getGameStatus(id: any) {
	return request({
		headers: headers(),
		baseURL,
		url: PATH + `/gameStatus/${id}`,
		method: 'get'
	})
}

export function getProvidersData() {
	return request({
		headers: headers(),
		baseURL,
		url: PATH + `/providerConf/list`,
		method: 'post'
	})
}

// export function getGameDetail(slug: any) {
// 	return request({
// 		headers: headers(),
// 		baseURL,
// 		url: PATH + `/betRecord/secondPage/${slug.id}`,
// 		method: 'get'
// 	})
// }

export function getGameDetail(slug: any) {
	return request({
		headers: headers(),
		baseURL,
		// url: PATH + `/betRecord/secondPage/${slug}`,
		url: PATH + `/betRecord/newSecondPage/${slug.id}`,
		method: 'get'
	})
}

export function getSlotsRecordDetailList(params: any) {
	return request({
		headers: headers(),
		baseURL,
		url: PATH + `/betRecord/detail/list`,
		method: 'get',
		params
	})
}
